<?php

namespace app\api\controller;

use think\Db;
use WebGeeker\Validation\Validation;

//定位相关
class Location
{
    public $mongo_obj;

    public function __construct()
    {
        try {
            $this->mongo_obj = Db::connect("db_mongo");
        }catch (\Exception $exception){
            errorBack($exception);
        }
    }

    //判断定位是否开通了城市
    public function isDredgeLocation()
    {
        try {
            // 验证（如果验证不通过，会抛出异常）
            Validation::validate($_GET, [
                "dredge_city_name" => "Required|Str|StrLenGe:1",  // 参数"count"是必需的且取值在 1 - 200 之间
            ]);


            $result = $this->mongo_obj->name('dredge_city')->where(['dredge_city_name'=>$_GET['dredge_city_name']])->field('dredge_city_status')->find();

            if(!$result){
                $dredge_city_status = 0;
            }else{
                $dredge_city_status = $result['dredge_city_status'];
            }

            successBack(['dredge_city_status'=>$dredge_city_status]);
        } catch (\Exception $exception) {
            errorBack($exception);
        }
    }

    //插入开通城市到mongo
    public function addDredgeLocation(){
        //$this->mongo_obj->name('dredge_city')->insertGetId(['dredge_city_name'=>'北京市','dredge_city_status'=>1,'dredge_city_time'=>time()]);
    }
}